﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class School_Manage_InputScore_upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnReqClsOK_ServerClick(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            try
            {
                //  保存文件
                DataSet ds = Meqs.Utilities.ExcelUtil.ExcelImport(FileUpload1.PostedFile.InputStream);
                if (ds.Tables.Count > 0)
                {
                    string[] frame = new string[ds.Tables[0].Columns.Count+1];
                    frame[0] = ds.Tables[0].TableName;
                    for (int i = 0; i < ds.Tables[0].Columns.Count;i++ )
                    {
                        frame[i + 1] = ds.Tables[0].Columns[i].Caption;
                    }

                    int stuCount = ds.Tables[0].Rows.Count;
                    int subCount = ds.Tables[0].Columns.Count-2;
                    string[] data = new string[(subCount+1)*stuCount];
                    for (int q = 0; q < data.Length; q++)
                    {
                        data[q] = "";
                    }
                    int j = 0;
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        data[j++] = (row[0] is DBNull) ? "" : row[0].ToString();
                        for (int k = 0; k < subCount; k++)
                        {
                            int tj = j++;
                            double temp = -2;
                            if (!(row[k + 2] is DBNull) && double.TryParse(row[k + 2].ToString(), out temp))
                            {
                                data[tj] = Math.Round(Convert.ToDouble( row[k + 2]),1).ToString();
                            }
                        }                       
                    }
                    string restr = "<script>var frame = new Array();var datas = new Array();";
                    for (int i=0;i< frame.Length;i++)
                    {
                        restr+="frame["+i+"]='"+frame[i]+"';";
                    }
                    for (int i = 0; i < data.Length; i++)
                    {
                        restr += "datas[" + i + "]='" + data[i] + "';";
                    }
                    restr += "parent.LoasExcel(frame,datas);</script>";
                    Response.Write(restr);
                }
                else
                { 
                    //错误文件
                    //Response.Write("<script>parent.ShowError('文件错误！')</script>");
                }
            }
            catch (Exception ex)
            {
                //Response.Write("<script>parent.ShowError('文件错误！')</script>");
            }
        }
        else
        {
            //Response.Write("<script>parent.ShowError('请输入文件！')</script>");
        }

    }
}
